
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package itm.dao.administracion;

//~--- non-JDK imports --------------------------------------------------------

import itm.exception.ControlException;

import itm.vo.administracion.TiposUsosVO;

//~--- JDK imports ------------------------------------------------------------

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author BISA20
 */
public class TiposUsoDAO {
    private CallableStatement callStmt = null;
    private ResultSet         res      = null;
    private String            sql      = "";
    Connection                dbConexion;

    public TiposUsoDAO(Connection dbConexion) {
        this.dbConexion = dbConexion;
    }

    public String crearTipoUso(TiposUsosVO tiposUsoVO) throws ControlException, SQLException {
        String aux = "";

        try {
            sql      = "{call ITM_CREAR_TIPO_USOS(?,?)}";
            callStmt = dbConexion.prepareCall(sql);
            callStmt.registerOutParameter(1, java.sql.Types.VARCHAR);
            callStmt.setString(2, tiposUsoVO.getNombreTipoUso());
            callStmt.execute();
            aux = callStmt.getString(1);
        } catch (SQLException ce) {
            ce.getStackTrace();
        }

        return aux;
    }

    public List<TiposUsosVO> consultarTiposUso(TiposUsosVO tiposUsosVO) throws ControlException, SQLException {
        List<TiposUsosVO> listaTipoUso = new ArrayList<TiposUsosVO>();

        try {
            sql      = "{call ITM_CONSULTAR_TIPO_USO(?)}";
            callStmt = dbConexion.prepareCall(sql);
            callStmt.setString(1, tiposUsosVO.getNombreTipoUso());
            res = callStmt.executeQuery();

            while (res.next()) {
                tiposUsosVO = new TiposUsosVO();
                tiposUsosVO.setNombreTipoUso(res.getString(1));
                tiposUsosVO.setIdTipoUso(res.getString(2));
                listaTipoUso.add(tiposUsosVO);
            }
        } catch (SQLException ce) {
            ce.getStackTrace();
        }

        return listaTipoUso;
    }

    public void eliminartipoUso(TiposUsosVO tiposUsosVO) throws ControlException, SQLException {
        try {
            sql      = "{call ITM_ELIMINAR_TIPO_USO(?)}";
            callStmt = dbConexion.prepareCall(sql);
            callStmt = dbConexion.prepareCall(sql);
            callStmt.setString(1, tiposUsosVO.getNombreTipoUso());
            res = callStmt.executeQuery();
        } catch (SQLException ce) {
            ce.getStackTrace();
        }
    }

    public String actualizarTipoUso(TiposUsosVO tiposUsosVO) throws ControlException, SQLException {
        String temp = "";

        try {
            sql      = "{call ITM_ACTUALIZAR_TIPO_USO(?,?,?)}";
            callStmt = (CallableStatement) dbConexion.prepareCall(sql);
            callStmt.registerOutParameter(1, java.sql.Types.VARCHAR);
            callStmt.setString(2, tiposUsosVO.getIdTipoUso());
            callStmt.setString(3, tiposUsosVO.getNombreTipoUso());
            callStmt.execute();
            temp = callStmt.getString(1);

            String qq = temp;
        } catch (SQLException ce) {
            ce.getStackTrace();
        }

        return temp;
    }
}
